using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using LHS.Core.CaseRecord.Classes;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;

namespace LHS.Win.SetUpCaseRecordForm.Forms
{
    public partial class ucMyRadioGroup : UserControl
    {
        public delegate void EditValueHandler(ucMyRadioGroup sender);
        public event EditValueHandler EditValueChanged;

        public ucMyRadioGroup()
        {
            InitializeComponent();
        }

        public String DisplayText
        {
            set
            {
                this.radioGroupMain.Properties.Items.Clear();
                String strText = value;
                String[] arrText = strText.Split(new Char[] { clsConstant.Radio_Group_Token }, StringSplitOptions.RemoveEmptyEntries);
                foreach (String text in arrText)
                {
                    if (text.Trim() != "")
                        this.radioGroupMain.Properties.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem(this.radioGroupMain.Properties.Items.Count, text.Trim()));
                }
            }
        }

        public Object EditValue
        {
            get { return this.radioGroupMain.EditValue; }
            set { this.radioGroupMain.EditValue = Math.Min(this.radioGroupMain.Properties.Items.Count, Convert.ToInt32(value == null || value == DBNull.Value || value.ToString() == "" ? "-1" : value)); }
        }

        public int Count
        {
            get { return this.radioGroupMain.Properties.Items.Count; }
        }

        public int Columns
        {
            get { return this.radioGroupMain.Properties.Columns; }
            set { this.radioGroupMain.Properties.Columns = Math.Max(value, 1); }
        }

        public IStyleController StyleController
        {
            get { return this.radioGroupMain.StyleController; }
            set { this.radioGroupMain.StyleController = value; }
        }

        public RepositoryItemRadioGroup Properties
        {
            get { return this.radioGroupMain.Properties; }
        }

        private void radioGroupMain_EditValueChanged(object sender, EventArgs e)
        {
            if (EditValueChanged != null)
                EditValueChanged(this);
        }

    }
}
